package cn.com.duiba.millionaire.center.biz.service.impl;

import cn.com.duiba.millionaire.center.api.dto.MillionaireConsumerAccountRecordDto;
import cn.com.duiba.millionaire.center.api.dto.PagenationDto;
import cn.com.duiba.millionaire.center.api.requestParam.AccountRecordRequestParam;
import cn.com.duiba.millionaire.center.biz.dao.MillionaireConsumerAccountRecordDao;
import cn.com.duiba.millionaire.center.biz.entity.MillionaireConsumerAccountRecordEntity;
import cn.com.duiba.millionaire.center.biz.service.ConsumerAccountRecordService;
import cn.com.duiba.wolf.utils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by qianjue on 2018/1/30.
 */
@Service
public class ConsumerAccountRecordServiceImpl implements ConsumerAccountRecordService {

	@Autowired
	MillionaireConsumerAccountRecordDao millionaireConsumerAccountRecordDao;

	@Override
	public PagenationDto<MillionaireConsumerAccountRecordDto> queryAccountRecordPage(
			AccountRecordRequestParam param) {
		PagenationDto<MillionaireConsumerAccountRecordDto> page = new PagenationDto<>();
		//查询数量
		int count = millionaireConsumerAccountRecordDao.queryAccountRecordPageCount(param);
		page.setTotal(count);
		if(count==0){
			return page;
		}
		List<MillionaireConsumerAccountRecordDto> list =
				BeanUtils.copyList(millionaireConsumerAccountRecordDao.queryAccountRecordPage(param),MillionaireConsumerAccountRecordDto.class);
		page.setList(list);
		return page;
	}

	@Override
	public List<MillionaireConsumerAccountRecordDto> queryAccountListByParam(
			AccountRecordRequestParam param) {
		return BeanUtils.copyList(millionaireConsumerAccountRecordDao.selectAccountListByParam(param),
				MillionaireConsumerAccountRecordDto.class);
	}

	@Override
	public MillionaireConsumerAccountRecordDto findByConsumerIdAndBizTypeAndBizId(Long consumerId, Integer bizType, String bizId) {
		MillionaireConsumerAccountRecordEntity entity = millionaireConsumerAccountRecordDao
				.findByConsumerIdAndBizTypeAndBizId(consumerId, bizType, bizId);
		return BeanUtils.copy(entity, MillionaireConsumerAccountRecordDto.class);
	}

	@Override
	public MillionaireConsumerAccountRecordDto insert(MillionaireConsumerAccountRecordDto millionaireConsumerAccountRecord) {
		MillionaireConsumerAccountRecordEntity entity = BeanUtils
				.copy(millionaireConsumerAccountRecord, MillionaireConsumerAccountRecordEntity.class);
		entity = millionaireConsumerAccountRecordDao.insert(entity);
		millionaireConsumerAccountRecord.setId(entity.getId());
		return millionaireConsumerAccountRecord;
	}
}
